Action hook 'comment_{$new_status}_{$comment->comment_type}'

in WP Core File wp-includes/comment.php at line 1896

View Source

comment_{$new_status}_{$comment->comment_type}

Action Hook
Description
Fires when the status of a specific comment type is in transition. The dynamic portions of the hook name, `$new_status`, and `$comment->comment_type`, refer to the new comment status, and the type of comment, respectively. Typical comment types include 'comment', 'pingback', or 'trackback'. Possible hook names include: - `comment_approved_comment` - `comment_approved_pingback` - `comment_approved_trackback` - `comment_unapproved_comment` - `comment_unapproved_pingback` - `comment_unapproved_trackback` - `comment_spam_comment` - `comment_spam_pingback` - `comment_spam_trackback`

Hook Information

File Location wp-includes/comment.php View on GitHub
Hook Type Action
Line Number 1896

Hook Parameters

Type Name Description
string $comment_id The comment ID as a numeric string.
WP_Comment $comment Comment object.

Usage Examples

Basic Usage
<?php
// Hook into comment_{$new_status}_{$comment->comment_type}
add_action('comment_{$new_status}_{$comment->comment_type}', 'my_custom_function', 10, 2);

function my_custom_function($comment_id, $comment) {
    // Your custom code here
}

Source Code Context

wp-includes/comment.php:1896 - How this hook is used in WordPress core
<?php
1891  	 * @since 2.7.0
1892  	 *
1893  	 * @param string     $comment_id The comment ID as a numeric string.
1894  	 * @param WP_Comment $comment    Comment object.
1895  	 */
1896  	do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment );
1897  }
1898  
1899  /**
1900   * Clears the lastcommentmodified cached value when a comment status is changed.
1901   *

PHP Documentation

<?php
/**
	 * Fires when the status of a specific comment type is in transition.
	 *
	 * The dynamic portions of the hook name, `$new_status`, and `$comment->comment_type`,
	 * refer to the new comment status, and the type of comment, respectively.
	 *
	 * Typical comment types include 'comment', 'pingback', or 'trackback'.
	 *
	 * Possible hook names include:
	 *
	 *  - `comment_approved_comment`
	 *  - `comment_approved_pingback`
	 *  - `comment_approved_trackback`
	 *  - `comment_unapproved_comment`
	 *  - `comment_unapproved_pingback`
	 *  - `comment_unapproved_trackback`
	 *  - `comment_spam_comment`
	 *  - `comment_spam_pingback`
	 *  - `comment_spam_trackback`
	 *
	 * @since 2.7.0
	 *
	 * @param string     $comment_id The comment ID as a numeric string.
	 * @param WP_Comment $comment    Comment object.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 2
  • File: wp-includes/comment.php
Related Hooks

Related hooks will be displayed here in future updates.